﻿// SyntheticDataGenerator.Core.Pattern
//
// (c) 2011 Arthur Pitman
//
// Part of Market-Basket Synthetic Data Generator
// A C# adaptation of the IBM Quest Market-Basket Synthetic Data Generator
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// (Version 2) as published by the Free Software Foundation.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License (Version 2) along with this program; if not, write to 
// the Free Software Foundation, Inc., 
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// or see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SyntheticDataGenerator.Core
{
	/// <summary>
	/// Represents a pattern
	/// </summary>
	public class Pattern
	{
		/// <summary>
		/// The items in the pattern
		/// </summary>
		public int[] Items { get; set; }

		/// <summary>
		/// Probability that this pattern is chosen
		/// </summary>
		public double Probability { get; set; }
		
		/// <summary>
		/// Probability that this pattern is corrrupted
		/// Used to decide how many items to drop from this pattern to corrupt it
		/// </summary>
		public double Confidence { get; set; }	

		/// <summary>
		/// The length of the pattern
		/// </summary>
		public int Length
		{
			get
			{
				return Items.Length;
			}
		}
				 
		/// <summary>
		/// Initializes a new <see cref="Pattern"/> instance
		/// </summary>
		/// <param name="length">Length of the pattern</param>
		/// <param name="probability"></param>
		/// <param name="confidence"></param>
		public Pattern(int length, double probability, double confidence)
		{
			Items = new int[length];
			Probability = probability;
			Confidence = confidence;
		}

		/// <summary>
		/// Writes the <see cref="Pattern"/> to the specified <see cref="TextWriter"/>
		/// </summary>
		/// <param name="writer"></param>
		public void Write(TextWriter writer)
		{
			writer.Write("{0} {1}", Probability , Confidence );
			foreach (var item in Items)
				writer.Write(" {0}", item);
			writer.WriteLine();            
		}	
	}
}
